
LIBNAME DISC "C:\Research\Insurance 23";

data imp_1990_2006_hosp_t1;
   set imp_1990_2006_hosp_t (keep = all medicaid private self_pay other_ins cntrl_public  cntrl_non_profit cntrl_for_profit  cntrl_other pregnant male  er_admit months_23);
run;

%macro pull_v(group,a_where);
Proc means data = imp_1990_2006_hosp_t1 noprint;
   var medicaid private self_pay other_ins;
   output out = junk1 (rename=(_FREQ_ = CA_&group.)) mean =  CA_medi_&group. CA_priv_&group. CA_self_&group. CA_o_ins_&group.;
   class &age_v.;
   where all = 1 &a_where.;
run;
Proc means data = imp_1990_2006_hosp_t1 noprint;
   var medicaid private self_pay other_ins;
   output out = junk2  (rename=(_FREQ_ = CA_&group._NED)) mean =  CA_medi_&group._NED CA_priv_&group._NED CA_self_&group._NED CA_o_ins_&group._NED;
   class &age_v.;
   where all = 1 &a_where. and er_admit = 0;
run;
Proc means data = imp_1990_2006_hosp_t1 noprint;
   var medicaid private self_pay other_ins;
   output out = junk3  (rename=(_FREQ_ = CA_&group._ED)) mean =  CA_medi_&group._ED CA_priv_&group._ED CA_self_&group._ED CA_o_ins_&group._ED;
   class &age_v.;
   where all = 1 &a_where. and er_admit = 1;
run;
data &group.;
   merge junk1 junk2 junk3;
   by &age_v.;
run;
proc datasets;
   delete junk1 junk2 junk3;
run;
%mend;



%macro insura(age_v); 
   %pull_v(all,);
   %pull_v(all_pub,and cntrl_public = 1);
   %pull_v(all_non_prof,and cntrl_non_profit = 1);
   %pull_v(all_for_prof,and cntrl_for_profit = 1);
   %pull_v(all_other,and cntrl_other = 1);
   %pull_v(all_np,and pregnant = 0);
   %pull_v(all_np_pub,and pregnant = 0 and cntrl_public = 1);
   %pull_v(all_np_non_prof,and pregnant = 0 and cntrl_non_profit = 1);
   %pull_v(all_np_for_prof,and pregnant = 0 and cntrl_for_profit = 1);
   %pull_v(all_np_other,and pregnant = 0 and cntrl_other = 1);
   %pull_v(female,and male = 0);
   %pull_v(female_pub,and male = 0 and cntrl_public = 1);
   %pull_v(female_non_prof,and male = 0 and cntrl_non_profit = 1);
   %pull_v(female_for_prof,and male = 0 and cntrl_for_profit = 1);
   %pull_v(female_other,and male = 0 and cntrl_other = 1);
   %pull_v(female_np,and male = 0 and pregnant = 0);
   %pull_v(female_np_pub,and male = 0 and pregnant = 0 and cntrl_public = 1);
   %pull_v(female_np_non_prof,and male = 0 and pregnant = 0 and cntrl_non_profit = 1);
   %pull_v(female_np_for_prof,and male = 0 and pregnant = 0 and cntrl_for_profit = 1);
   %pull_v(female_np_other,and male = 0 and pregnant = 0 and cntrl_other = 1);
   %pull_v(male,and male = 1);
   %pull_v(male_pub,and male = 1 and cntrl_public = 1);
   %pull_v(male_non_prof,and male = 1 and cntrl_non_profit = 1);
   %pull_v(male_for_prof,and male = 1 and cntrl_for_profit = 1);
   %pull_v(male_other,and male = 1 and cntrl_other = 1);
   data disc.ins_23_reprod_CA (drop = _type_ );
      merge all 		all_pub 		all_non_prof 		all_for_prof 		all_other
       	 	all_np 		all_np_pub 		all_np_non_prof 	all_np_for_prof 	all_np_other
         	female 		female_pub 		female_non_prof 	female_for_prof 	female_other
   		 	female_np 	female_np_pub 	female_np_non_prof 	female_np_for_prof 	female_np_other
   		 	female_p 	female_p_pub 	female_p_non_prof 	female_p_for_prof 	female_p_other
   		 	male 		male_pub 		male_non_prof 		male_for_prof 		male_other;
      by &age_v.;
      merge_v = 1;
   run;
PROC EXPORT DATA= disc.ins_23_reprod_CA
            OUTFILE= "C:\Research\Insurance 23\Hosp_Insurance_by_months_23.csv" 
            DBMS=csv REPLACE;
RUN;
%mend;

%insura(months_23);


